package threading;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @author 徐志荣
 * @date 2023/3/19 16:01
 */
public class ThreadDemo19 {
    public static void main(String[] args) throws InterruptedException {

       // BlockingDeque<String> queue = new ArrayBlockingQueue<>();
        BlockingDeque<String> queue2 = new LinkedBlockingDeque<>();
        //阻塞队列的核心方法,主要有两个
        //1. put入队列
        queue2.put("hello1");
        queue2.put("hello2");
        queue2.put("hello3");
        queue2.put("hello4");
        queue2.put("hello5");

        //2. take 出队列
        String result = null;
         result = queue2.take();
        System.out.println(result);
        result = queue2.take();
        System.out.println(result);
        result = queue2.take();
        System.out.println(result);
        result = queue2.take();
        System.out.println(result);
        result = queue2.take();
        System.out.println(result);
        result = queue2.take();
        System.out.println(result);
/*
*   上述代码中 put5次 take6次,第6次的时候阻塞了
*
* */


    }
}
